﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Maticsoft.Common;
using Maticsoft.DBUtility;
using System.Web;
using MyHelper;
using Aspose.Words;
using System.Drawing.Imaging;
using System.Text.RegularExpressions;
using System.Linq.Expressions;
using System.Data.SqlClient;
using System.Reflection;
using System.Collections.Specialized;
using System.Security.Cryptography;
using System.IO;
using System.Data.Linq.SqlClient;
using System.Data.Linq;
using System.Xml;
using Maticsoft.Common.DEncrypt;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
namespace Test
{
   
    class Program
    {

      
        static void Main(string[] args)
        {

           
            
        }
        
        public static string GetPropertyName(Expression expression, bool getAll = true)
        {
            if (expression == null)
            {
                return "";
            }
            MemberExpression me = null;
            LambdaExpression le = null;
            if (expression is MemberExpression)
            {
                me = expression as MemberExpression;
            }
            if (expression is LambdaExpression)
            {
                le = expression as LambdaExpression;
                if (le.Body is MemberExpression)
                {
                    me = le.Body as MemberExpression;
                }
                if (le.Body is UnaryExpression)
                {
                    me = (le.Body as UnaryExpression).Operand as MemberExpression;
                }
            }
            string rv = "";
            if (me != null)
            {
                rv = me.Member.Name;
            }
            while (me != null && getAll && me.NodeType == ExpressionType.MemberAccess)
            {
                Expression exp = me.Expression;
                if (exp is MemberExpression)
                {
                    rv = (exp as MemberExpression).Member.Name + "." + rv;
                    me = exp as MemberExpression;
                }
                else if (exp is MethodCallExpression)
                {
                    var mexp = exp as MethodCallExpression;
                    if (mexp.Method.Name == "get_Item")
                    {
                        var obj = ((mexp.Arguments[0] as MemberExpression).Expression as ConstantExpression).Value;
                        var index = obj.GetType().GetField((mexp.Arguments[0] as MemberExpression).Member.Name).GetValue(obj);
                        rv = (mexp.Object as MemberExpression).Member.Name + "[" + index + "]." + rv;
                        me = mexp.Object as MemberExpression;
                    }
                }
                else
                {
                    break;
                }
            }
            return rv;
        }
      
   


        class Classes
        {
            public int CID { get; set; }
            public string ClassName { get; set; }
            public string  DD { get; set; }
            public Student s1 { get; set; }
        }
        public class Student
        {
            public int ID { get; set; }
            public string Name { get; set; }
            public int ClassID { get; set; }
            public List<int> Scroes { get; set; }
        }
        public class Student2
        {
            public List<int> Scores { get; set; }
            public string Name { get; set; }
        }
        public class Tree : ITreeData<Tree>
        {

            public IEnumerable<Tree> GetChildren()
            {
                throw new NotImplementedException();
            }

            public Tree Parent
            {
                get { throw new NotImplementedException(); }
            }

            public long? ParentID
            {
                get
                {
                    throw new NotImplementedException();
                }
                set
                {
                    throw new NotImplementedException();
                }
            }
        }
        public interface ITreeData
        {
            //父节点ID
            long? ParentID { get; set; }
        }
        /// <summary>
        /// 泛型树形结构model接口
        /// </summary>
        /// <typeparam name="T">父节点类型，父节点应该和实现本接口的类是同一个类，否则没有意义</typeparam>
        public interface ITreeData<out T> : ITreeData 
        {
            /// <summary>
            /// 通过实现这个函数获得所有的子节点数据
            /// </summary>
            /// <returns>所有子节点数据</returns>
            IEnumerable<T> GetChildren();
            //获取父节点
            T Parent { get; }
        }
    }  
}
